#include "httputil.h"

#include <unistd.h>
#include <cstdio>
const string HTTPUtil::methodString(HTTPMethod method)
{
    if (method == MethodGET)
        return "GET";
    else if (method == MethodPOST)
        return "POST";
    else if (method == MethodHEAD)
        return "HEAD";
    else
        return "ERROR";
}

bool HTTPUtil::readline(string& str, bool *eof, int fd) {
    str.clear();
    ssize_t nread;
    char read_char;
    *eof = false;
    while ((nread = read(fd, &read_char, 1)) != -1) {
        if (nread == 0) {
            *eof = true;
            return true;
        }
        if (read_char != '\n')
            str.append(1, read_char);
        else
            return true;
    }
    perror("readline");
    return false;
}
